<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2023-04-30 12:22:02
 * @LastEditors: wiz
 * @LastEditTime: 2023-11-04 17:18:13
-->
<template>
  <div>
    <oSimpleToolbar
      :compBoxInfo="GT_compBoxInfo"
      :list="G_list"
      @click="btnClick"
      :compID="G_compID"
    />
  </div>
</template>

<script lang="ts">
import {
  Tsrv,
  T_srv,
  ts,
  ifs,
  defaultToolbarList,
  N_oFlowchart,
  N_oSimpleToolbar,
  vue
} from './config';

@T_srv.comp({
  components: {}
})
export default class ruleToolbar extends vue {
  @T_srv.prop({ required: true, type: Array, default: [] }) toolbarConf: Array<
    N_oSimpleToolbar.I_Conf
  >;

  // 父组件compBoxInfo
  @T_srv.prop({
    required: false,
    type: Object,
    default: null
  })
  compBoxInfo: ifs.I_compBoxInfo;

  private GT_compBoxInfo: ifs.I_compBoxInfo;

  private GT_compBox: ifs.I_compBox;

  private G_compID: string;

  private G_toolMap = new Map();

  private G_list: Array<N_oSimpleToolbar.I_Conf> = defaultToolbarList();

  created() {
    this.G_list.forEach(o => this.G_toolMap.set(o.key, o));
    this.GT_compBoxInfo = this.compBoxInfo;
    this.G_compID = this.GT_compBoxInfo.compID;
    this.GT_compBox = this.GT_compBoxInfo.TcompBox;
    this.GT_compBox.addCompMergeName(this.G_compID, `editToolbar`, this);
    this.toolbarConf.length > 0 &&
      (this.G_list[this.G_list.length - 1].separator = true);
    this.toolbarConf.forEach(item => {
      if (!this.G_toolMap.has(item.key)) {
        this.G_list.push(item);
        this.G_toolMap.set(item.key, item);
      }
    });
  }

  mounted() {
    // for (const obj of this.toolbarConf) {
    //   const o: any = obj;
    //   this.G_toolMap.set(o.key, obj);
    // }
  }

  destroyed() {
    this.GT_compBox.removeCompMergeName(this.G_compID, `editToolbar`);
  }

  hideToolbarItem(name: string) {
    for (const [idx, o] of this.G_list.entries()) {
      if (o.key.toLowerCase() === name.toLowerCase()) {
        this.G_list[idx]['isHide'] = true;
        return;
      }
    }
  }

  btnClick(item, e) {
    this.GT_compBox.getCompMergeName(
      this.G_compID,
      `graphToolbar`
    ).graphToolbarClick(item, e);
  }

  screenChange = (): void => {
    if (this.G_list.findIndex(el => el.key === 'fullScreen') !== -1) {
      const btnScreen = this.G_list.filter(el => el.key === 'fullScreen');
      btnScreen[0].class === 'wy-ios-expand'
        ? (btnScreen[0].class = 'wy-ios-contract')
        : (btnScreen[0].class = 'wy-ios-expand');
    }
  };
}
</script>
